home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue61 / Construc / TDM61.DPR < prev    next >
Encoding:
Text File  |  2000-08-07  |  3.0 KB  |  139 lines

  1. program TDM61;
  2. {$APPTYPE CONSOLE}
  3. uses
  4.   SysUtils, MMSystem;
  5.  
  6.   // resourcestring
  7.  
  8.   function CaptionMaker1(Str: ShortString): ShortString;
  9.   { stack: 256 (arg) + 256 (local) + 256 (result) bytes }
  10.   var
  11.     i: Integer;
  12.     Tmp: ShortString;
  13.   begin
  14.     Tmp := Str; // initial copy
  15.     for i:=1 to Length(Str) do
  16.       if (i = 1) or (Str[i-1] = #32) then
  17.         Tmp[i] := UpCase(Str[i])
  18.       else
  19.         Tmp[i] := Str[i];
  20.     Result := Tmp;
  21.   end;
  22.  
  23.   function CaptionMaker2(Str: ShortString): ShortString;
  24.   { stack: 256 (arg) + 256 (result) bytes }
  25.   var
  26.     i: Integer;
  27.   begin
  28.     for i:=1 to Length(Str) do
  29.       if (i = 1) or (Str[i-1] = #32) then
  30.         Str[i] := UpCase(Str[i]);
  31.     Result := Str
  32.   end;
  33.  
  34.   function CaptionMaker3(const Str: ShortString): ShortString;
  35.   { stack: 256 (result) bytes }
  36.   var
  37.     i: Integer;
  38.   begin
  39.     Result := Str; // initial copy
  40.     for i:=1 to Length(Str) do
  41.       if (i = 1) or (Str[i-1] = #32) then
  42.         Result[i] := UpCase(Str[i])
  43.   end;
  44.  
  45.   procedure CaptionMaker4(var Str: ShortString);
  46.   var
  47.     i: Integer;
  48.   begin
  49.     for i:=1 to Length(Str) do
  50.       if (i = 1) or (Str[i-1] = #32) then
  51.         Str[i] := UpCase(Str[i])
  52.   end;
  53.  
  54.   function CaptionMaker5(var Str: ShortString): PShortString;
  55.   var
  56.     i: Integer;
  57.   begin
  58.     for i:=1 to Length(Str) do
  59.       if (i = 1) or (Str[i-1] = #32) then
  60.         Str[i] := UpCase(Str[i]);
  61.     Result := @Str
  62.   end;
  63.  
  64.   function ReadFile(const FileName: ShortString): String;
  65.   var
  66.     f: Text;
  67.     Line,Str: String;
  68.   begin
  69.     Str := '';
  70.     Assign(f,FileName);
  71.     Reset(f);
  72.     while not eof(f) do
  73.     begin
  74.       readln(f,Line);
  75.       Str := Str + #13#10 + Line { re-allocate Str }
  76.     end;
  77.     Close(f);
  78.     Result := Str
  79.   end;
  80.  
  81. var
  82.   Str: ShortString;
  83.   Str2: ShortString;
  84.   EndTime: Cardinal;
  85.   Reps: Integer;
  86.   Ch: WideChar;
  87. var
  88.   X: Array[0..42] of Char;
  89.   Y: PChar;
  90. begin
  91.   X := 'this is a null-terminated string';
  92.   Y := X; { pointer Y points to X now }
  93.   Y[0] := 'T';
  94.   writeln(X);
  95.  
  96.   Str := 'this is a short string to test';
  97.   Ch := Chr(256 + 32);
  98.   writeln(Ord(Ch));
  99.   Str2 := '';
  100. //SetLength(Str2,1);
  101. //if Str2[11] = #32 then writeln('access violation');
  102.  
  103.   Reps := 0;
  104.   EndTime := TimeGetTime + 100;
  105.   repeat
  106.     Inc(Reps);
  107.     Str2 := CaptionMaker1(Str);
  108.   until TimeGetTime > EndTime;
  109.   writeln('1: ',Reps);
  110.   Reps := 0;
  111.   EndTime := TimeGetTime + 100;
  112.   repeat
  113.     Inc(Reps);
  114.     Str2 := CaptionMaker2(Str);
  115.   until TimeGetTime > EndTime;
  116.   writeln('2: ',Reps);
  117.   Reps := 0;
  118.   EndTime := TimeGetTime + 100;
  119.   repeat
  120.     Inc(Reps);
  121.     Str2 := CaptionMaker3(Str);
  122.   until TimeGetTime > EndTime;
  123.   writeln('3: ',Reps);
  124.   Reps := 0;
  125.   EndTime := TimeGetTime + 100;
  126.   repeat
  127.     Inc(Reps);
  128.     CaptionMaker4(Str);
  129.   until TimeGetTime > EndTime;
  130.   writeln('4: ',Reps);
  131.   Reps := 0;
  132.   EndTime := TimeGetTime + 100;
  133.   repeat
  134.     Inc(Reps);
  135.     Str2 := CaptionMaker5(Str)^;
  136.   until TimeGetTime > EndTime;
  137.   writeln('5: ',Reps);
  138.   readln
  139. end.